package servlet;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Method;

public class BaseServlet extends HttpServlet{
    @Override
    public void doGet(HttpServletRequest request,HttpServletResponse response){
        doPost(request,response);
    }



    @Override
    public void doPost(HttpServletRequest request, HttpServletResponse response)
    {
        //处理乱码
        try {
            request.setCharacterEncoding("utf-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        String action=request.getParameter("action");

        //采用反射直接动态调用
        try {
            Method method=this.getClass().getDeclaredMethod(action,HttpServletRequest.class,HttpServletResponse.class);
            method.invoke(this,request,response);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

}
